//
//  RBForgetPsdController.m
//  StoryToy
//
//  Created by baxiang on 2017/10/17.
//  Copyright © 2017年 roobo. All rights reserved.
//

#import "RBForgetPsdController.h"
#import "ReactiveObjC.h"
#import "RBResetPsdController.h"
#import "RTLineTextField.h"
#import <RBToyAPI/RBToyAPI.h>
#import "UIImage+RBExtension.h"

@interface RBForgetPsdController ()<UITextFieldDelegate>
/** 手机号 */
@property (nonatomic, weak) RTLineTextField * phoneTxtV;
@end

@implementation RBForgetPsdController


#pragma mark ------------------- lifeCycle ------------------------
#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"找回密码";
    self.view.backgroundColor = [UIColor whiteColor];
    
    RTLineTextField *phoneTxtV = [RTLineTextField new];
    phoneTxtV.placeholder = @"请输入手机号";
    phoneTxtV.returnKeyType = UIReturnKeyNext;
    phoneTxtV.textColor = UIColorHex(576166);
    phoneTxtV.keyboardType = UIKeyboardTypePhonePad;
    phoneTxtV.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:phoneTxtV];
    _phoneTxtV = phoneTxtV;
    [phoneTxtV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(45);
        make.right.mas_equalTo(-45);
        make.height.mas_equalTo(45);
        make.top.mas_equalTo(90);
    }];
     [phoneTxtV becomeFirstResponder];
    
   
    UIButton * getVerifyCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [getVerifyCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [getVerifyCodeBtn addTarget:self action:@selector(getVerifyCodeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [getVerifyCodeBtn setBackgroundImage:[UIImage imageWithColor:RTColorForBackground] forState:UIControlStateNormal];
//    [getVerifyCodeBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(c0c0c1)] forState:UIControlStateDisabled];
    [self.view addSubview:getVerifyCodeBtn];
    getVerifyCodeBtn.layer.masksToBounds = YES;
     getVerifyCodeBtn.layer.cornerRadius = 45*0.5;
    [getVerifyCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(phoneTxtV.mas_left);
        make.right.mas_equalTo(phoneTxtV.mas_right);
        make.height.mas_equalTo(45);
        make.top.mas_equalTo(phoneTxtV.mas_bottom).offset(45);
    }];
  
    [phoneTxtV.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        if (x.length>10) {
             getVerifyCodeBtn.enabled = YES;
        }else{
            getVerifyCodeBtn.enabled = NO;
        }
    }];
}

- (void)getVerifyCodeBtnClick{
    NSString *phoneNum = self.phoneTxtV.text;
    RBResetPsdController * resetVC=  [RBResetPsdController new];
    resetVC.phoneNum = phoneNum;
    [self.navigationController pushViewController:resetVC animated:YES];
}


@end
